﻿@{
    ViewBag.Title = "Product";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>产品管理</title>
     <script src="~/libs/jquery/jquery.js"></script>
    <link href="//unpkg.com/layui@2.9.16/dist/css/layui.css" rel="stylesheet">
    <script src="//unpkg.com/layui@2.9.16/dist/layui.js"></script>
   @*  <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet"> *@
</head>
<body>
    <form class="layui-form layui-row">
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">产品编号：</label>
                <input type="text" style="width:170px" id="ProductCode" value="" placeholder="请输入产品编号" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">产品名称：</label>
                <input type="text" style="width:170px" id="ProductName" value="" placeholder="请输入产品名称" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-btn-container ">
            <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
        </div>
    </form>
    <table class="layui-hide" id="test"></table>
    <div style="position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);">
        <button class="layui-btn" onclick="add()">确定</button>
        <button class="layui-btn layui-btn-danger" onclick="cancel()">取消</button>
    </div>
   @*  <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script> *@
    <script>
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var dropdown = layui.dropdown;
        var util = layui.util;
        function cancel() {
            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
            parent.layer.close(index);//再执行关闭
        }
        function add() {
            // 获取选中行数据并将名称传给父页面
            var checkStatus = table.checkStatus('test');
            var data = checkStatus.data;
            if (data.length == 0) {
                layer.msg("请选择数据");
                return;
            }
            // 将选择的数据传递给父页面
            window.parent.receiveData(data);
            // 关闭当前弹出层
            cancel();
        }
        layui.use(function () {
            //显示
            function show() {
                table.render({
                    elem: '#test',
                    url: '/QiData/GetProduct',
                    page: true, //开启分页
                    limit: 10,
                    limits: [10, 20, 50, 100],
                    cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'productCode', title: '产品编号', width: 150, fixed: 'left' },
                        { field: 'productName', title: '产品名称', width: 120 },
                        { field: 'productSpecification', title: '规格', width: 150 },
                        { field: 'category', title: '类别', width: 120 },
                        { field: 'unit', title: '单位', width: 100 },
                        { field: 'unitPrice', title: '单价', width: 100 },
                    ]],
                });
            }
            show();//初始化显示
            // 搜索提交
            form.on('submit(demo-table-search)', function (data) {
                var recptname = $("#ProductCode").val();
                var vendorname = $("#ProductName").val();
                // 执行搜索重载
                table.reload('test', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    },
                    where: {
                        ProductCode: recptname,
                        ProductName: vendorname,
                    }// 搜索的字段
                });
                return false; // 阻止默认 form 跳转
            });
        });
    </script>
</body>
</html>
